/**
 * Created by yangfan on 2016/8/15.
 */
define(["business/services/constant"], function (constant) {
    //var baseUrl = "http://10.10.10.12:8080";
   // var baseUrl = "http://192.168.1.14:8081";
        var baseUrl = "http://"+allUrl+":8083";
    //var NewsUrl ="http://192.168.0.25:8080";
    var NewsUrl ="http://"+allUrl+":8085";
    var topCategory = "elink_database/api/category";
    var fileType = "elink_database/api/type/list";
    var getList = "elink_database/api/file/getList";
    var downLoadRank = "elink_database/api/file/getDownLoadRank";
    var relevantType = "elink_database/api/file/getRelevantType";
    var getFile = "elink_database/api/file/get";
    var getShare = "elink_database/api/file/getShare";
    var getLike = "elink_database/api/file/getLike";
    var CONSTANT_FILE = "elink_database/api/file";
    var CONSTANT_COLLECTION = "elink_database/api/collection";
    var CONSTANT_COMMENT = "elink_database/api/comment";
    var CONSTANT_NEWS = "elink_news/api/news";
    var CONSTANT_NEWSCOMMENT = "elink_news/api/comment";


    var register = "elink_user/api/user/checkEmail";
    var tag_api = constant.config.COONSTANT_DATATAG;
    var injector = angular.injector(["ng"]);
    var token = "seed="+ localStorage.seed + "&authToken=" + localStorage.authToken;
    var filterRequestion = function(requestion){
         if(requestion.data){
             var str="";
             for(var key in requestion.data){
                 if(requestion.data[key]==="undefined"||requestion.data[key]===""||requestion.data[key]==NaN||requestion.data[key]==null){
                    //类型错误 或需要被过滤
                 }else{
                     str += key +"="+requestion.data[key]+"&"
                 }
             }
             str = str.substr(0,str.lastIndexOf("&"));

             return str + "&" + token;
         }
    };
    return {

        checkEmail:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:"http://115.29.168.57:9000"+"/"+register+"/"+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getTopCategory:function(requestion){
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+ topCategory +"/"+requestion.param +"?"+ token
                })
            };
            return  injector.invoke(httpSend)
        },
            getSecondCategory:function (requestion) {
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+ topCategory +"/"+requestion.param+"?tcId="+requestion.tcId +"&"+ token
                })
            };
            return  injector.invoke(httpSend)
        },
        getDetailCategory:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+ topCategory +"/"+requestion.param+"?" + str
                })
            };
            return  injector.invoke(httpSend)
        },
        getFileType :function(requestion){
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+ fileType +"?"+ token
                })
            };
            return  injector.invoke(httpSend)
        },
        getList:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+ getList +"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getDownLoadRank:function(requestion){
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+downLoadRank+"?count="+ requestion.count +'&mold='+requestion.data.mold+"&tcId="+requestion.data.tcId
                })
            };
            return  injector.invoke(httpSend)
        },
        getRelevantType:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+relevantType+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getRelevant:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+CONSTANT_FILE+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getKeyWord:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+CONSTANT_FILE+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getFile:function(requestion){
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+getFile+"?fileId="+requestion.fileId +"&"+ token
                })
            };
            return  injector.invoke(httpSend)
        },
        getFileShare:function(requestion){
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+getShare+"?fileId="+requestion.fileId +"&"+ token
                })
            };
            return  injector.invoke(httpSend)
        },
        getLike:function (requestion)  {
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+getLike+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getComment:function (requestion) {
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+CONSTANT_COMMENT+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        addComment:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+CONSTANT_COMMENT+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        addPraise:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+CONSTANT_COMMENT+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        //新闻详情接口
        getNews:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:NewsUrl+"/"+CONSTANT_NEWS+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getNewsLike:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:NewsUrl+"/"+CONSTANT_NEWS+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getNewsHotRank:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:NewsUrl+"/"+CONSTANT_NEWS+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getNewsRelevantType:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:NewsUrl+"/"+CONSTANT_NEWS+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getNewsRelevant:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:NewsUrl+"/"+CONSTANT_NEWS+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        getTopCommentsByNewsId:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:NewsUrl+"/"+CONSTANT_NEWSCOMMENT+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        addFile:function(requesion){
            return constant.httpSend(baseUrl,CONSTANT_FILE,requesion);
        },
        updateCollection:function(requestion){
            var str = filterRequestion(requestion);
            var httpSend = function($http){
                return $http({
                    method: requestion.type,
                    url:baseUrl+"/"+CONSTANT_COLLECTION+"/"+requestion.uri+"?"+str
                })
            };
            return  injector.invoke(httpSend)
        },
        tagServices:function(requestion){
            return constant.httpSend(baseUrl,tag_api,requestion);
        },
		downloadHttpService:function(requesion){
   			return constant.httpSend(baseUrl,CONSTANT_FILE,requesion);
   		},
        getPreviewPng:function(requesion){
            //var localURL = 'http://192.168.0.31:8080' ;
            return constant.httpSend(baseUrl,CONSTANT_FILE,requesion);
        }

    }
});
